
/* GCSx
** SPAWNEDIT.H
**
** Spawn-point editor-only functionality
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_SPAWNEDIT_H_
#define __GCSx_SPAWNEDIT_H_

class SpawnEdit : public Spawn {
protected:
    // Who owns us
    class WorldEdit* world;
    class LayerEdit* layer; // If NULL, then no sprite in properties dialog
    
    // Are we associated with a world/layer now- i.e. store undo?
    // Set on load or when requested
    int undoReady;
    
    // Can be locked by layer/etc
    int lockCount;
    
    // We only display spawns in the editor, so we only need
    // display-related data there
    int displayX; // modified for any offset
    int displayY;
    int displayW;
    int displayH;
    void calculateDisplayCoords();
    
    // Tell our owner we're modified
    void setModified();

public:
    // ID of zero if loading or clipboard
    SpawnEdit(class WorldEdit* myWorld, class LayerEdit* myLayer, int newId = 0);
    // (since a new spawnedit isn't locked, won't lock anything it copies)
    SpawnEdit(const class SpawnEdit* copy, class LayerEdit* myLayer, int newId = 0);
    virtual ~SpawnEdit();
    // (doesn't mark old/new layer as modified; no Undo here)
    void setLayer(class LayerEdit* newLayer);
    void setUndoReady();
    class LayerEdit* getLayer() { return layer; }
    int getW() const { return displayW; }
    int getH() const { return displayH; }

    // So we lock our anim/image (not script)
    int markLock() throw_File;
    int markUnlock();
    int isLocked() const;
    void load(class FileRead* file, const class World* world) throw_File;
    
    // Change properties
    void setName(const std::string& newName, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
    void setPos(int nX, int nY, int skipUndo = 0, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
    void setSprite(class AnimGroup* newAnimgroup, class TileSet* newTileset, int newId, Window* srcWin = NULL, Window* exWin = NULL) throw_File throw_Undo;
    void setScript(class Script* newScript, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
    
    // Display in editor
    // dim 1 = half dim (for dimmed sprite layers)
    // dim 2 = 75% dim (for sprite placement hover)
    void blit(int offsetX, int offsetY, SDL_Surface* dest, int clipX, int clipY, int clipW, int clipH, int dim = 0, int selection = 0);
    
    // Returns true if OK pressed
    int propertiesDialog(Window* srcWin = NULL, Window* exWin = NULL);

    // Save data to file
    void save(class FileWrite* file) throw_File;
};

#endif
